package com.cymal.controller;

import com.cymal.SubjectEngine;
import com.cymal.entity.bo.Result;
import com.cymal.entity.bo.SubjectRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 判题搜寻控制器
 */
@RestController
@RequestMapping("/api/engine")
public class SubjectController {


    /**
     * 题目引擎
     */
    private final SubjectEngine engine;


    /**
     * Constructor.
     * @param engine 引擎
     */
    public SubjectController(SubjectEngine engine) {
        this.engine = engine;
    }


    /**
     * match and search.
     * @param req 请求
     * @return (true or false) and result.
     */
    @PostMapping("/search")
    public ResponseEntity<Result> matchAndSearch(@RequestBody SubjectRequest req) {
        Result result = engine.matched(req.getSubject(), req.getReqs());
        return ResponseEntity.ok(result);
    }


}
